package com.info.game;


import com.component.game.Component;
import com.component.game.InputComponent;
import com.engine.game.GameObject;
import com.engine.game.MessageInfo;


public class GravityRobotInputComponent implements InputComponent{

	@Override
	public void dispose() {
		
		
	}

	@Override
	public void update(GameObject object) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
		

		for(MessageInfo message : object.getInputMessages()){
			
			if(message.message.contains("key") && message.message.contains("went_down")){
				
				String[] parts = message.message.split(";");
				
				if(parts[1].equals("W")){
					object.generate("jump_up", object.name, Component.Physics);
				}
				else if(parts[1].equals("A")){
					object.generate("walk_left", object.name, Component.Physics);
					object.generate("walk_left", object.name, Component.Render);
					
				}
				else if(parts[1].equals("S")){
					object.generate("jump_down", object.name, Component.Physics);
				}
				else if(parts[1].equals("D")){
					object.generate("walk_right", object.name, Component.Physics);
					object.generate("walk_right", object.name, Component.Render);
				}
				else if(parts[1].equals("F")){
				
					object.generate("inverse", object.name, Component.Physics);
					object.generate("inverse", object.name, Component.Render);
					object.generate("power", object.name, Component.Render);
				}
				else if(parts[1].equals("E")){
					object.generate("open", object.name, Component.Physics);
				}
				
				
			}
			else if(message.message.contains("key") && message.message.contains("went_up")){
				
				String[] parts = message.message.split(";");
				
				if(parts[1].equals("A")){
					GravityRobotPhysicsComponent.stop = true;
					
				//	object.generate("stop", object.name, Component.Physics);
					object.generate("stop", object.name, Component.Render);
					
				}
				else if(parts[1].equals("D")){
					GravityRobotPhysicsComponent.stop = true;
					
				//	object.generate("stop", object.name, Component.Physics);
					object.generate("stop", object.name, Component.Render);
				}
				
				
			}
			
		}
		
		
	}

}
